//
//  LoginC.m
//  UniverseProject
//
//  Created by king on 2019/9/3.
//  Copyright © 2019年 Cloud2209. All rights reserved.
//


#import "BOTextField.h"
#import "LoginC.h"

@interface LoginC ()

@property (nonatomic, weak)BOTextField *loginPhoneT;
@property (nonatomic, weak)BOTextField *loginPasswordT;
@property (nonatomic, weak)UIImageView *topLogo;
@property (nonatomic, weak)UIButton *loginBtn;

@end

@implementation LoginC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.gesture_handel = YES;
    self.hideNavBar = YES;
    [self setUpUI];
}



- (void)setUpUI
{
    
    CGFloat padding = 42;
    CGFloat maxW = K_SCREEN_WIDTH - padding * 2;
    
    UIImageView *topLogo = [UIImageView new];
    [topLogo setImage:LGIMAGE(@"integrals_top_Bg")];
    topLogo.contentMode = UIViewContentModeScaleAspectFit;
    topLogo.backgroundColor = LGCOLOR(@"222222");
    topLogo.frame = CGRectMake((K_SCREEN_WIDTH - 170) / 2, 95, 170, 51);
    [self.view addSubview:topLogo];
    self.topLogo = topLogo;
    
    BOTextField *textField;
    for (int i = 0; i < 2; i++) {
        textField = [BOTextField setUpTextFieldFrame:CGRectMake(padding,topLogo.bottom + 95 + i * 54, maxW, 44) Placeholder:i == 0 ? @"输入用户名" : @"输入密码" textColor:@"#333333" placeholderColor:@"#DDDDDD" textFont:13 leftImageName:@"gray_holder_20" leftImageW:30 leftImageH:20 maxChars:i == 0 ? 11 : 20];
        [self.view addSubview:textField];
        [textField addLineWithFrame:CGRectMake(0, 43, maxW, 1) color:LGCOLOR(@"#EDEDED")];
        if (i == 0) {
            self.loginPhoneT = textField;
//            textField.keyboardType = UIKeyboardTypeNumberPad;
        } else {
            textField.secureTextEntry = YES;
            self.loginPasswordT = textField;
            
            UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(textField.width - 54, 0, 54, 44)];
            [textField addSubview:btn];
            [btn setImage:LGIMAGE(@"mimaaw") forState:UIControlStateNormal];
            [btn setImage:LGIMAGE(@"mimamw") forState:UIControlStateSelected];
            [btn addTarget:self action:@selector(passwordBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    
    for (int i = 0; i < 2; i++) {
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(i == 0 ? padding : padding + maxW - 100, CGRectGetMaxY(self.loginPasswordT.frame), 100, 44)];
        btn.titleLabel.font = LGFONT(12);
        [self.view addSubview:btn];
        btn.tag = i + 1;
        [btn setTitle:i == 0 ? @"记住密码" : @"自动登录" forState:UIControlStateNormal];
        [btn jk_setImagePosition:LXMImagePositionLeft spacing:7];
        btn.contentHorizontalAlignment = i == 0 ? UIControlContentHorizontalAlignmentLeft : UIControlContentHorizontalAlignmentRight;
        [btn setTitleColor:LGCOLOR(@"#585951") forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(funcClick:) forControlEvents:UIControlEventTouchUpInside];
        [btn setImage:LGIMAGE(@"gray_holder_20") forState:UIControlStateNormal];
    }
    
    UIButton *loginBtn = [UIButton defaultBtnWithFrame:CGRectMake(padding, CGRectGetMaxY(self.loginPasswordT.frame) + 72, maxW, 49) Title:@"登录" target:self action:@selector(loginClick:)];
    [self.view addSubview:loginBtn];
    self.loginBtn = loginBtn;

    UIButton *scanBtn = [UIButton buttonWithTitle:@"扫码注册" titleColor:LGCOLOR(@"#585953") font:LGFONT(18) target:self action:@selector(scanClick)];
    [scanBtn setImage:LGIMAGE(@"gray_holder_20") forState:UIControlStateNormal];
    scanBtn.frame = CGRectMake(0, loginBtn.bottom + 87, K_SCREEN_WIDTH, 44);
    [self.view addSubview:scanBtn];
    [scanBtn jk_setImagePosition:LXMImagePositionLeft spacing:12];
 
    UILabel *bottomLab = [UILabel labelWithTitle:@"忘记密码请联系项目管理员重置" color:LGCOLOR(@"#CCCCCC") font:LGFONT(12)];
    bottomLab.frame = CGRectMake(0, K_SCREEN_HEIGHT - 42, K_SCREEN_WIDTH, 42);
    bottomLab.textAlignment = 1;
    [self.view addSubview:bottomLab];

    //调整登录按钮颜色
    loginBtn.alpha = 0.5;
}


// 密码明文、暗文切换按钮
- (void)passwordBtnClick:(UIButton *)btn
{
    btn.selected = !btn.selected;
    self.loginPasswordT.secureTextEntry = !btn.selected;
}


- (void)loginClick:(UIButton *)btn{
    
    
}

- (void)funcClick:(UIButton *)btn{
    
    
}


- (void)scanClick{
    
    Class PushClass = NSClassFromString(@"ScanViewC");
    PushVC([PushClass new]);
    
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self dismissViewControllerAnimated:YES completion:nil];
}



@end
